package com.ruoyi.basics.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.basics.domain.vo.WmsGoodsVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basics.domain.WmsGoods;
import com.ruoyi.basics.service.IWmsGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货品管理Controller
 * 
 * @author ruoyi
 * @date 2025-06-11
 */
@RestController
@RequestMapping("/basics/WmsGoods")
public class WmsGoodsController extends BaseController
{
    @Autowired
    private IWmsGoodsService wmsGoodsService;

    /**
     * 查询货品管理列表
     */
    @PreAuthorize("@ss.hasPermi('basics:WmsGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsGoodsVo wmsGoodsvo)
    {
        startPage();
        List<WmsGoodsVo> list = wmsGoodsService.selectWmsGoodsList(wmsGoodsvo);
        return getDataTable(list);
    }

    /**
     * 获取货品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('basics:WmsGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wmsGoodsService.selectWmsGoodsById(id));
    }

    /**
     * 生成货品编码的接口
     * @return 新生成的货品编码，如 HP000001
     */
    @GetMapping("/maxCode")
    public AjaxResult getMaxCode(){
        String maxCode = wmsGoodsService.selectMaxCode();
        return AjaxResult.success("查询成功",maxCode);
    }

    /**
     * 新增货品管理
     */
    @PreAuthorize("@ss.hasPermi('basics:WmsGoods:add')")
    @Log(title = "货品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsGoods wmsGoods)
    {
        return toAjax(wmsGoodsService.insertWmsGoods(wmsGoods));
    }

    /**
     * 修改货品管理
     */
    @PreAuthorize("@ss.hasPermi('basics:WmsGoods:edit')")
    @Log(title = "货品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsGoods wmsGoods)
    {
        return toAjax(wmsGoodsService.updateWmsGoods(wmsGoods));
    }

    /**
     * 删除货品管理
     */
    @PreAuthorize("@ss.hasPermi('basics:WmsGoods:remove')")
    @Log(title = "货品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsGoodsService.deleteWmsGoodsByIds(ids));
    }
}
